
<%
function renderTreeNode(node, prefix) {
  prefix = prefix || '';
  const children = node.children || [];
  %>
    <li>
          <%= prefix %><%= node.name %>
          
            <a href="<%=removeURL%>?id=<%= node._id%>" class="btn btn-danger btn-link">删除</a>
            <span class="btn btn-danger btn-link" 
            data-toggle="modal"
            data-target="#<%= node._id %>">新增</span>
          <% if (children.length) { %>
            <ul style="margin-left: 28px;">
              <% children.forEach(function(child) { %>
                <%= renderTreeNode(child, prefix + '  ') %>
              <% }) %>
            </ul>
          <% } %>

              
              <div
                class="modal fade"
                id="<%= node._id %>"
                tabindex="-1"
                role="dialog"
                
              >
                <div class="modal-dialog" role="document">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button
                        type="button"
                        class="close"
                        data-dismiss="modal"
                        aria-label="Close"
                      >
                        <span aria-hidden="true">&times;</span>
                      </button>
                      <h4 class="modal-title" id="exampleModalLabel">添加分类</h4>
                    </div>
                    <div class="modal-body">
                      <form action="/content/categories/create" method="post">
                        <div class="form-group">
                          <label for="recipient-name" class="control-label"
                            >父级id:</label>
                          <input
                            type="text"
                            class="form-control"
                            id="recipient-name"
                            name="parentId"
                            value="<%= node._id %>"
                          />
                        </div>
                        <div class="form-group">
                          <label for="recipient-name" class="control-label"
                            >分类名称:</label
                          >
                          <input
                            type="text"
                            class="form-control"
                            id="recipient-name"
                            name="name"
                          />
                        </div>
                        <div class="modal-footer">
                          <button
                            type="button"
                            class="btn btn-default"
                            data-dismiss="modal"
                          >
                            关闭
                          </button>
                          <button class="btn btn-primary" type="submit">保存</button>
                        </div>
                      </form>
                    </div>
                  </div>
                </div>
              </div>
        </li>
    
  <%
}
%>

<ul>
  <% tree.forEach(function(item) { %>
    <% renderTreeNode(item) %> 
  <% }) %>
</ul>
